package com.example.qggoodsprovider.service.impl;
import com.example.qggoodsprovider.mapper.GoodsMapper;
import com.example.qggoodsprovider.service.GoodsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Service
@Transactional
public class GoodsServiceImpl implements GoodsService {

    @Resource
    private GoodsMapper mapper;
    @Override
    public List<Map> getAllGoods() {
        return mapper.getAllGoods();
    }

    @Override
    public int getQgTotalByGoodsId(int goodsId) {
        return mapper.getQgTotalByGoodsId( goodsId );
    }


    public List<Map> getAllGoodsByQgTotal(){
        List<Map> allGoods = getAllGoods();
//        if (allGoods!=null)
            for (Map goods:allGoods){
                int qgTotal =  getQgTotalByGoodsId( (Integer) goods.get( "id" ) );
                goods.put( "qgTotal",qgTotal );
                //计算还剩多少
                goods.put( "currStock",(Integer) goods.get( "stock" )-qgTotal);
            }
//        }

        return allGoods;

    }

    @Override
    public int getStock(int goodsId) {
        return mapper.getStock( goodsId );
    }

    @Override
    public int addTempSotck(Map map) {
        return mapper.addTempSotck( map );
    }

    @Override
    public int getCountByGoodsIdUid( Map map) {
        return mapper.getCountByGoodsIdUid(map);
    }

    @Override
    public Map getById(int goodsId) {
        return mapper.getById(goodsId);
    }

}
